package com.zxc.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.project.pojo.Variety;
import com.zxc.project.service.VarietyService;
import org.springframework.stereotype.Service;
import com.zxc.project.mapper.VarietyMapper;
import com.zxc.project.pojo.query.VarietyQuery;

@Service
public class VarietyServiceImpl extends ServiceImpl<VarietyMapper, Variety> implements VarietyService {

    @Override
    public boolean save(Variety variety) {
        if(variety.getId() == null) {
            //保存时stock就是新增时的这个
            variety.setStock(variety.getTotal().intValue());
        } else {
            //todo 修改时判断逻辑
        }
        return super.save(variety);
    }

    @Override
    public IPage<Variety> page(IPage<Variety> page, VarietyQuery varietyQuery) {
        return baseMapper.selectQueryPage(page, varietyQuery);
    }
}
